package com.guigu.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.erp.mapper.SysUsersMapper;
import com.guigu.erp.pojo.DesignFile;
import com.guigu.erp.pojo.SysUsers;
import com.guigu.erp.service.SysUsersService;
import com.guigu.erp.utils.PageUtils;
import com.guigu.erp.vo.SysUsersVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: janecraft
 * @Date: 2024/5/16
 * @Description: com.guigu.erp.service.impl
 * @Version： 1.0
 */
@Service
public class SysUsersServiceImpl extends ServiceImpl<SysUsersMapper, SysUsers>
        implements SysUsersService {



    @Override
    public PageUtils<SysUsers> page(SysUsersVo vo, int pageNo, int pageSize) {
        QueryWrapper<SysUsers> wrapper = new QueryWrapper<>();
        if(vo != null) {
            // TODO
        }
        PageHelper.startPage(pageNo, pageSize);
        List<SysUsers> list = list(wrapper);
        PageInfo<SysUsers> usersPageInfo = new PageInfo<>(list);

        //将pageinfo 转换成 pageutils
        PageUtils<SysUsers> pageUtils = new PageUtils<>();
        pageUtils.setRows(usersPageInfo.getList());
        pageUtils.setTotal(usersPageInfo.getTotal());
        return pageUtils;
    }

    @Override
    public SysUsers getSysUserByName(String username) {
        QueryWrapper<SysUsers> wrapper = new QueryWrapper<>();
        wrapper.eq("login_id", username);
        List<SysUsers> list = list(wrapper);
        if(list.size() > 0)
            return list.get(0);
        return null;
    }
}
